package net.xdclass.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/ai")
public class DefaultChatClientController {

    @Autowired
    private ChatClient chatClient;

    @GetMapping(value = "/default_client", produces = "text/html;charset=UTF-8")
    public String generate(@RequestParam("msg") String msg) {
        String content = this.chatClient.prompt()
                .user(msg)
                .call()
                .content();

        return content;
    }

    @GetMapping(value = "/stream_client", produces = "text/html;charset=UTF-8")
    public Flux<String> stream(@RequestParam("msg") String msg) {
        return this.chatClient.prompt()
                .user(msg)
                .stream()
                .content();
    }
}
